/*
 * CS_REQ_MAGIC_REFINE_INFO.cpp
 *
 *  Created on: 2014. 3. 24.
 *      Author: mega
 */

#include "../../Command.h"
#include "../../User.h"
#include "../../NResource/ItemMagicRefineResource.h"
#include "../../NResource/Static.h"

namespace ProjectZ { namespace NCommand {

static void SendFailMagicRefineInfo(User * pUser, int ack)
{
	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	*pAck << static_cast<int16_t>(ack);
	pAck->MakePacket(CMD_SC_REQ_MAGIC_REFINE_INFO);
	pUser->Send(pAck);
}

void Command::CS_REQ_MAGIC_REFINE_INFO(User * pUser, ::Network::Packet * pPacket)
{
/*	// 마법 제련 성공률 정보 요청
	ZNO_CS_REQ_MAGIC_REFINE_INFO 			0x220A
	{

	}

	// 제련 응답
	ZNO_SC_REQ_MAGIC_REFINE_INFO 			0x220B
	{
		s16	s16_ack;
		u8 u8stone_rate;		// 마법석 추가 성공룔
		u8 u8count;
		{
			u16	u16success_rate;	// 단계별 기본 성공률
		}
	}*/

	PREPARE_PACKET;

	NResource::ItemMagicRefineResource::Flyweight * pFly = NULL;

	pFly = NResource::Static::Instance().GetMagicRefineResource()->GetFly(NResource::ItemMagicRefineResource::MagicRefineType::MAGIC_STONE_RATE);
	if (NULL == pFly)
	{
		DEBUGLOG("%s : pFly is NULL", __FUNCTION__);
		SendFailMagicRefineInfo(pUser, ACK_UNKNOWN_ERROR);
		return;
	}

	int magicStoneRate = pFly->_VALUE;

	std::vector<int> clsValueVector;
	int startIndex	= static_cast<int>(NResource::ItemMagicRefineResource::MagicRefineType::MAGIC_REFINE_RATE_1);
	int endIndex	= static_cast<int>(NResource::ItemMagicRefineResource::MagicRefineType::MAGIC_REFINE_RATE_5);
	for (; startIndex <= endIndex; startIndex++)
	{
		pFly = NResource::Static::Instance().GetMagicRefineResource()->GetFly(static_cast<NResource::ItemMagicRefineResource::MagicRefineType>(startIndex));
		if (NULL == pFly)
		{
			DEBUGLOG("%s : pFly is NULL. idx=%d", __FUNCTION__, startIndex);
			SendFailMagicRefineInfo(pUser, ACK_UNKNOWN_ERROR);
			return;
		}

		clsValueVector.push_back(pFly->_VALUE);
	}

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	*pAck << static_cast<int16_t>(ACK_OK);
	*pAck << static_cast<uint8_t>(magicStoneRate);
	*pAck << static_cast<uint8_t>(clsValueVector.size());

	auto iter = clsValueVector.begin();
	for (; iter != clsValueVector.end(); ++iter)
	{
		*pAck << static_cast<uint16_t>( (* iter) );
	}

	pAck->MakePacket(CMD_SC_REQ_MAGIC_REFINE_INFO);
	pUser->Send(pAck);
}

} /*NCommand*/ } /*ProjectZ*/
